//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS SSOOIDC service.
///
/// IAM Identity Center OpenID Connect (OIDC) is a web service that enables a client (such as CLI or a native application) to register with IAM Identity Center. The service also enables the client to fetch the user’s access token upon successful authentication and authorization with IAM Identity Center.  API namespaces  IAM Identity Center uses the sso and identitystore API namespaces. IAM Identity Center OpenID Connect uses the sso-oauth namespace.  Considerations for using this guide  Before you begin using this guide, we recommend that you first review the following important information about how the IAM Identity Center OIDC service works.   The IAM Identity Center OIDC service currently implements only the portions of the OAuth 2.0 Device Authorization Grant standard (https://tools.ietf.org/html/rfc8628) that are necessary to enable single sign-on authentication with the CLI.    With older versions of the CLI, the service only emits OIDC access tokens, so to obtain a new token, users must explicitly re-authenticate. To access the OIDC flow that supports token refresh and doesn’t require re-authentication, update to the latest CLI version (1.27.10 for CLI V1 and 2.9.0 for CLI V2) with support for OIDC token refresh and configurable IAM Identity Center session durations. For more information, see Configure Amazon Web Services access portal session duration .    The access tokens provided by this service grant access to all Amazon Web Services account entitlements assigned to an IAM Identity Center user, not just a particular application.   The documentation in this guide does not describe the mechanism to convert the access token into Amazon Web Services Auth (“sigv4”) credentials for use with IAM-protected Amazon Web Services service endpoints. For more information, see GetRoleCredentials in the IAM Identity Center Portal API Reference Guide.   For general information about IAM Identity Center, see What is IAM Identity Center? in the IAM Identity Center User Guide.
public struct SSOOIDC: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the SSOOIDC client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "SSOOIDC",
            serviceIdentifier: "oidc",
            signingName: "sso-oauth",
            serviceProtocol: .restjson,
            apiVersion: "2019-06-10",
            endpoint: endpoint,
            serviceEndpoints: Self.serviceEndpoints,
            errorType: SSOOIDCErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }


    /// custom endpoints for regions
    static var serviceEndpoints: [String: String] {[
        "af-south-1": "oidc.af-south-1.amazonaws.com",
        "ap-east-1": "oidc.ap-east-1.amazonaws.com",
        "ap-northeast-1": "oidc.ap-northeast-1.amazonaws.com",
        "ap-northeast-2": "oidc.ap-northeast-2.amazonaws.com",
        "ap-northeast-3": "oidc.ap-northeast-3.amazonaws.com",
        "ap-south-1": "oidc.ap-south-1.amazonaws.com",
        "ap-south-2": "oidc.ap-south-2.amazonaws.com",
        "ap-southeast-1": "oidc.ap-southeast-1.amazonaws.com",
        "ap-southeast-2": "oidc.ap-southeast-2.amazonaws.com",
        "ap-southeast-3": "oidc.ap-southeast-3.amazonaws.com",
        "ap-southeast-4": "oidc.ap-southeast-4.amazonaws.com",
        "ap-southeast-5": "oidc.ap-southeast-5.amazonaws.com",
        "ca-central-1": "oidc.ca-central-1.amazonaws.com",
        "ca-west-1": "oidc.ca-west-1.amazonaws.com",
        "cn-north-1": "oidc.cn-north-1.amazonaws.com.cn",
        "cn-northwest-1": "oidc.cn-northwest-1.amazonaws.com.cn",
        "eu-central-1": "oidc.eu-central-1.amazonaws.com",
        "eu-central-2": "oidc.eu-central-2.amazonaws.com",
        "eu-north-1": "oidc.eu-north-1.amazonaws.com",
        "eu-south-1": "oidc.eu-south-1.amazonaws.com",
        "eu-south-2": "oidc.eu-south-2.amazonaws.com",
        "eu-west-1": "oidc.eu-west-1.amazonaws.com",
        "eu-west-2": "oidc.eu-west-2.amazonaws.com",
        "eu-west-3": "oidc.eu-west-3.amazonaws.com",
        "il-central-1": "oidc.il-central-1.amazonaws.com",
        "me-central-1": "oidc.me-central-1.amazonaws.com",
        "me-south-1": "oidc.me-south-1.amazonaws.com",
        "sa-east-1": "oidc.sa-east-1.amazonaws.com",
        "us-east-1": "oidc.us-east-1.amazonaws.com",
        "us-east-2": "oidc.us-east-2.amazonaws.com",
        "us-gov-east-1": "oidc.us-gov-east-1.amazonaws.com",
        "us-gov-west-1": "oidc.us-gov-west-1.amazonaws.com",
        "us-west-1": "oidc.us-west-1.amazonaws.com",
        "us-west-2": "oidc.us-west-2.amazonaws.com"
    ]}



    // MARK: API Calls

    /// Creates and returns access and refresh tokens for clients that are authenticated using client secrets. The access token can be used to fetch short-lived credentials for the assigned AWS accounts or to access application APIs using bearer authentication.
    @Sendable
    @inlinable
    public func createToken(_ input: CreateTokenRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> CreateTokenResponse {
        try await self.client.execute(
            operation: "CreateToken", 
            path: "/token", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Creates and returns access and refresh tokens for clients that are authenticated using client secrets. The access token can be used to fetch short-lived credentials for the assigned AWS accounts or to access application APIs using bearer authentication.
    ///
    /// Parameters:
    ///   - clientId: The unique identifier string for the client or application. This value comes from the result of the RegisterClient API.
    ///   - clientSecret: A secret string generated for the client. This value should come from the persisted result of the RegisterClient API.
    ///   - code: Used only when calling this API for the Authorization Code grant type. The short-lived code is used to identify this authorization request.
    ///   - codeVerifier: Used only when calling this API for the Authorization Code grant type. This value is generated by the client and presented to validate the original code challenge value the client passed at authorization time.
    ///   - deviceCode: Used only when calling this API for the Device Code grant type. This short-lived code is used to identify this authorization request. This comes from the result of the StartDeviceAuthorization API.
    ///   - grantType: Supports the following OAuth grant types: Authorization Code, Device Code, and Refresh Token. Specify one of the following values, depending on the grant type that you want: * Authorization Code - authorization_code  * Device Code - urn:ietf:params:oauth:grant-type:device_code  * Refresh Token - refresh_token
    ///   - redirectUri: Used only when calling this API for the Authorization Code grant type. This value specifies the location of the client or application that has registered to receive the authorization code.
    ///   - refreshToken: Used only when calling this API for the Refresh Token grant type. This token is used to refresh short-lived tokens, such as the access token, that might expire. For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.
    ///   - scope: The list of scopes for which authorization is requested. This parameter has no effect; the access token will always include all scopes configured during client registration.
    ///   - logger: Logger use during operation
    @inlinable
    public func createToken(
        clientId: String,
        clientSecret: String,
        code: String? = nil,
        codeVerifier: String? = nil,
        deviceCode: String? = nil,
        grantType: String,
        redirectUri: String? = nil,
        refreshToken: String? = nil,
        scope: [String]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> CreateTokenResponse {
        let input = CreateTokenRequest(
            clientId: clientId, 
            clientSecret: clientSecret, 
            code: code, 
            codeVerifier: codeVerifier, 
            deviceCode: deviceCode, 
            grantType: grantType, 
            redirectUri: redirectUri, 
            refreshToken: refreshToken, 
            scope: scope
        )
        return try await self.createToken(input, logger: logger)
    }

    /// Creates and returns access and refresh tokens for authorized client applications that are authenticated using any IAM entity, such as a service role or user. These tokens might contain defined scopes that specify permissions such as read:profile or write:data. Through downscoping, you can use the scopes parameter to request tokens with reduced permissions compared to the original client application's permissions or, if applicable, the refresh token's scopes. The access token can be used to fetch short-lived credentials for the assigned Amazon Web Services accounts or to access application APIs using bearer authentication.  This API is used with Signature Version 4. For more information, see Amazon Web Services Signature Version 4 for API Requests.
    @Sendable
    @inlinable
    public func createTokenWithIAM(_ input: CreateTokenWithIAMRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> CreateTokenWithIAMResponse {
        try await self.client.execute(
            operation: "CreateTokenWithIAM", 
            path: "/token?aws_iam=t", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Creates and returns access and refresh tokens for authorized client applications that are authenticated using any IAM entity, such as a service role or user. These tokens might contain defined scopes that specify permissions such as read:profile or write:data. Through downscoping, you can use the scopes parameter to request tokens with reduced permissions compared to the original client application's permissions or, if applicable, the refresh token's scopes. The access token can be used to fetch short-lived credentials for the assigned Amazon Web Services accounts or to access application APIs using bearer authentication.  This API is used with Signature Version 4. For more information, see Amazon Web Services Signature Version 4 for API Requests.
    ///
    /// Parameters:
    ///   - assertion: Used only when calling this API for the JWT Bearer grant type. This value specifies the JSON Web Token (JWT) issued by a trusted token issuer. To authorize a trusted token issuer, configure the JWT Bearer GrantOptions for the application.
    ///   - clientId: The unique identifier string for the client or application. This value is an application ARN that has OAuth grants configured.
    ///   - code: Used only when calling this API for the Authorization Code grant type. This short-lived code is used to identify this authorization request. The code is obtained through a redirect from IAM Identity Center to a redirect URI persisted in the Authorization Code GrantOptions for the application.
    ///   - codeVerifier: Used only when calling this API for the Authorization Code grant type. This value is generated by the client and presented to validate the original code challenge value the client passed at authorization time.
    ///   - grantType: Supports the following OAuth grant types: Authorization Code, Refresh Token, JWT Bearer, and Token Exchange. Specify one of the following values, depending on the grant type that you want: * Authorization Code - authorization_code  * Refresh Token - refresh_token  * JWT Bearer - urn:ietf:params:oauth:grant-type:jwt-bearer  * Token Exchange - urn:ietf:params:oauth:grant-type:token-exchange
    ///   - redirectUri: Used only when calling this API for the Authorization Code grant type. This value specifies the location of the client or application that has registered to receive the authorization code.
    ///   - refreshToken: Used only when calling this API for the Refresh Token grant type. This token is used to refresh short-lived tokens, such as the access token, that might expire. For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.
    ///   - requestedTokenType: Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that the requester can receive. The following values are supported: * Access Token - urn:ietf:params:oauth:token-type:access_token  * Refresh Token - urn:ietf:params:oauth:token-type:refresh_token
    ///   - scope: The list of scopes for which authorization is requested. The access token that is issued is limited to the scopes that are granted. If the value is not specified, IAM Identity Center authorizes all scopes configured for the application, including the following default scopes: openid, aws, sts:identity_context.
    ///   - subjectToken: Used only when calling this API for the Token Exchange grant type. This value specifies the subject of the exchange. The value of the subject token must be an access token issued by IAM Identity Center to a different client or application. The access token must have authorized scopes that indicate the requested application as a target audience.
    ///   - subjectTokenType: Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that is passed as the subject of the exchange. The following value is supported: * Access Token - urn:ietf:params:oauth:token-type:access_token
    ///   - logger: Logger use during operation
    @inlinable
    public func createTokenWithIAM(
        assertion: String? = nil,
        clientId: String,
        code: String? = nil,
        codeVerifier: String? = nil,
        grantType: String,
        redirectUri: String? = nil,
        refreshToken: String? = nil,
        requestedTokenType: String? = nil,
        scope: [String]? = nil,
        subjectToken: String? = nil,
        subjectTokenType: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> CreateTokenWithIAMResponse {
        let input = CreateTokenWithIAMRequest(
            assertion: assertion, 
            clientId: clientId, 
            code: code, 
            codeVerifier: codeVerifier, 
            grantType: grantType, 
            redirectUri: redirectUri, 
            refreshToken: refreshToken, 
            requestedTokenType: requestedTokenType, 
            scope: scope, 
            subjectToken: subjectToken, 
            subjectTokenType: subjectTokenType
        )
        return try await self.createTokenWithIAM(input, logger: logger)
    }

    /// Registers a public client with IAM Identity Center. This allows clients to perform authorization using the authorization code grant with Proof Key for Code Exchange (PKCE) or the device code grant.
    @Sendable
    @inlinable
    public func registerClient(_ input: RegisterClientRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> RegisterClientResponse {
        try await self.client.execute(
            operation: "RegisterClient", 
            path: "/client/register", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Registers a public client with IAM Identity Center. This allows clients to perform authorization using the authorization code grant with Proof Key for Code Exchange (PKCE) or the device code grant.
    ///
    /// Parameters:
    ///   - clientName: The friendly name of the client.
    ///   - clientType: The type of client. The service supports only public as a client type. Anything other than public will be rejected by the service.
    ///   - entitledApplicationArn: This IAM Identity Center application ARN is used to define administrator-managed configuration for public client access to resources. At authorization, the scopes, grants, and redirect URI available to this client will be restricted by this application resource.
    ///   - grantTypes: The list of OAuth 2.0 grant types that are defined by the client. This list is used to restrict the token granting flows available to the client. Supports the following OAuth 2.0 grant types: Authorization Code, Device Code, and Refresh Token.  * Authorization Code - authorization_code  * Device Code - urn:ietf:params:oauth:grant-type:device_code  * Refresh Token - refresh_token
    ///   - issuerUrl: The IAM Identity Center Issuer URL associated with an instance of IAM Identity Center. This value is needed for user access to resources through the client.
    ///   - redirectUris: The list of redirect URI that are defined by the client. At completion of authorization, this list is used to restrict what locations the user agent can be redirected back to.
    ///   - scopes: The list of scopes that are defined by the client. Upon authorization, this list is used to restrict permissions when granting an access token.
    ///   - logger: Logger use during operation
    @inlinable
    public func registerClient(
        clientName: String,
        clientType: String,
        entitledApplicationArn: String? = nil,
        grantTypes: [String]? = nil,
        issuerUrl: String? = nil,
        redirectUris: [String]? = nil,
        scopes: [String]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> RegisterClientResponse {
        let input = RegisterClientRequest(
            clientName: clientName, 
            clientType: clientType, 
            entitledApplicationArn: entitledApplicationArn, 
            grantTypes: grantTypes, 
            issuerUrl: issuerUrl, 
            redirectUris: redirectUris, 
            scopes: scopes
        )
        return try await self.registerClient(input, logger: logger)
    }

    /// Initiates device authorization by requesting a pair of verification codes from the authorization service.
    @Sendable
    @inlinable
    public func startDeviceAuthorization(_ input: StartDeviceAuthorizationRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> StartDeviceAuthorizationResponse {
        try await self.client.execute(
            operation: "StartDeviceAuthorization", 
            path: "/device_authorization", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Initiates device authorization by requesting a pair of verification codes from the authorization service.
    ///
    /// Parameters:
    ///   - clientId: The unique identifier string for the client that is registered with IAM Identity Center. This value should come from the persisted result of the RegisterClient API operation.
    ///   - clientSecret: A secret string that is generated for the client. This value should come from the persisted result of the RegisterClient API operation.
    ///   - startUrl: The URL for the Amazon Web Services access portal. For more information, see Using the Amazon Web Services access portal in the IAM Identity Center User Guide.
    ///   - logger: Logger use during operation
    @inlinable
    public func startDeviceAuthorization(
        clientId: String,
        clientSecret: String,
        startUrl: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StartDeviceAuthorizationResponse {
        let input = StartDeviceAuthorizationRequest(
            clientId: clientId, 
            clientSecret: clientSecret, 
            startUrl: startUrl
        )
        return try await self.startDeviceAuthorization(input, logger: logger)
    }
}

extension SSOOIDC {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: SSOOIDC, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}
